<template>
  <div class="user-info">
    <el-row :span="24">
      <el-col :span="8">
        <basic-container>
          <div class="user-info__content">
            <img class="user-info__img"
                 :src="useAvatarUrl"
                 @click="$ImagePreview(userFormModel.avatar)"
                 alt=""/>
            <p class="user-info__name">{{ userFormModel.userFinalName }}</p>
            <router-link class="user-info__setting"
                         :to="{path:'/info/setting'}">个人设置
            </router-link>
            <p class="user-info__desc">{{ userFormModel.remarks }}</p>
            <div class="user-info__detail-desc">
              <p><i class="el-icon-message"></i><span>{{ userFormModel.yx }}</span></p>
              <p><i class="el-icon-postcard"></i><span>{{ userFormModel.gs }} · {{
                  userFormModel.bm
                }} · {{ userFormModel.zw }}</span></p>
              <p><i class="el-icon-location-information"></i><span>{{ userFormModel.dz }}</span></p>
            </div>
            <div class="user-info__divider"></div>
            <h4>标签</h4>
            <div class="user-info__tags">
              <el-tag effect="plain"
                      v-for="(tag,index) in tags"
                      :key="index">
                {{ tag }}
              </el-tag>
            </div>
          </div>
        </basic-container>
      </el-col>
      <el-col :span="16">
        <basic-container>
          <el-tabs v-model="activeName">
            <el-tab-pane label="个人信息"
                         :name="0">
              <el-form label-width="110px">
                <el-form-item label="">
                  <div style="width: 100%">
                    <div class="" style="margin:auto">
                      <start-avatar v-model="userFormModel.avatar" size="large"></start-avatar>
                    </div>
                  </div>
                </el-form-item>
                <el-form-item label=" 昵称">
                  <el-input v-model="userFormModel.nickName"></el-input>
                </el-form-item>
                <el-form-item label="姓名">
                  <el-input v-model="userFormModel.realName"></el-input>
                </el-form-item>

                <el-form-item label="用户名">
                  <div>{{ userFormModel.userName }}</div>
                </el-form-item>
                <el-form-item label="手机号">
                  <el-input v-model="userFormModel.phone"></el-input>
                </el-form-item>
                <el-form-item label="邮箱">
                  <el-input v-model="userFormModel.email"></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="submitUserInfo">确认</el-button>
                  <el-button>取消</el-button>
                </el-form-item>
              </el-form>
            </el-tab-pane>
            <el-tab-pane label="修改密码"
                         :name="1">
              <start-update-user-pwd ref="startUpdateUserPwd"
                                     :user-id="userFormModel.id"
              >
                <el-form-item label="">
                  <el-button type="primary" @click="submitUserPwd">确认</el-button>
                  <el-button @click="$refs.startUpdateUserPwd.rest()">重置</el-button>
                </el-form-item>
              </start-update-user-pwd>
            </el-tab-pane>
          </el-tabs>
        </basic-container>
      </el-col>
    </el-row>

  </div>
</template>

<script>
import useUserStore from "@/stores/useUserStore";
import {getUploadConfig} from "@/config/env";
import {deepClone} from "utils/util";
import StartUpdateUserPwd from "components/start-components/startDpdateUserPwd/index.vue";
import {updateCurrentUserPassword} from "@/api/user";
import StartAvatar from "components/start-components/startAvatar/index.vue";

const uploadConfig = getUploadConfig();
export default {
  components: {StartAvatar, StartUpdateUserPwd},
  computed: {
    uploadConfig() {
      return uploadConfig
    },
    useAvatarUrl() {
      let avatar = this.userFormModel.avatar
      if (!avatar) {
        return null;
      }
      if (!Array.isArray(avatar)) {
        return avatar;
      }
      return avatar[0]
    }
  },
  data() {
    return {
      activeName: 0,
      tags: [],
      userFormModel: {},
      userStore: useUserStore(),
    };
  },

  created() {
    let userInfo = this.userStore.userInfo;
    userInfo = deepClone(userInfo)
    this.userFormModel = userInfo;

  },
  methods: {

    submitUserInfo() {
      console.log("handleSubmit", this.userFormModel);
      this.userStore.updateUserInfo(deepClone(this.userFormModel))
      // this.$message({
      //   message: this.userFormModel,
      //   type: "success"
      // });
    },
    submitUserPwd() {
      this.$refs.startUpdateUserPwd.submitData().then(res => {
        return updateCurrentUserPassword(res)
      }).then(res => {
        this.$message.success("密码修改成功")
        this.$refs.startUpdateUserPwd.rest()
      })
    },
    handleChange(item) {
      this.type = item.prop;
    }
  }
}

</script>

<style lang="scss">
.user-info {
  .avue-tabs {
    padding: 0 10px;
  }

  .el-tabs__content {
    padding: 20px 0;
  }

  &__img {
    display: block;
    margin: 0 auto;
    border-radius: 100%;
    width: 100px;
    height: 100px;
  }

  &__name {
    text-align: center;
    font-size: 20px;
    line-height: 28px;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.85);
    margin-bottom: 0;
    margin-top: 10px;
  }

  &__setting {
    margin-bottom: 12px;
    display: block;
    font-size: 12px;
    color: #409eff;
    text-align: center;
  }

  &__desc {
    text-align: center;
    width: 200px;
    margin: 0 auto;
  }

  &__detail-desc {
    margin-top: 50px;
    font-size: 14px;

    p {
      margin-bottom: 10px;
    }

    span {
      margin-left: 10px;
    }
  }

  &__divider {
    border-top: 1px dashed #e8e8e8;
    display: block;
    height: 0;
    width: 100%;
    margin: 24px 0;
    clear: both;
  }

  &__tags {
    .el-tag {
      margin: 0 5px 5px 0;
    }
  }
}
</style>
